package com.xiaomi.shop.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xiaomi.shop.entity.ProductInfo;
import com.xiaomi.shop.entity.ProductInfoExample;
import com.xiaomi.shop.entity.ProductVO;
import com.xiaomi.shop.mapper.ProductInfoMapper;
import com.xiaomi.shop.service.ProductInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName 陈欣月
 * @Descripttion TODO
 * @Author cxy
 * @Date 2021/10/13 19:37
 * @Version 1.0
 **/
@Service
public class ProductInfoServiceImpl implements ProductInfoService {
    @Autowired
    private ProductInfoMapper productInfoMapper;
    @Override
    public PageInfo<ProductInfo> selectConditionSplitPage(ProductVO productVO, int pageSize) {
       //先设置分页
        PageHelper.startPage(productVO.getPage(),pageSize);
        //获取集合
        List<ProductInfo> list = productInfoMapper.selectConditionSplitPage(productVO);

        PageInfo<ProductInfo> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public PageInfo splitPage(int page, int pageSize) {
        ProductInfoExample example = new ProductInfoExample();//产品信息查询类

        //设置分页启动代码
        //先设置分页
        PageHelper.startPage(page,pageSize);
        //检索所有的数据
        List<ProductInfo> list = productInfoMapper.selectByExample(example);
        //获取pegeinfo对象
        PageInfo<ProductInfo> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public void deleteByPrimaryKey(Integer pId) {
        productInfoMapper.deleteByPrimaryKey(pId);

    }

    @Override
    public void save(ProductInfo productInfo) {
        productInfoMapper.insertSelective(productInfo);
    }


}
